import {
	createI18n
} from 'vue-i18n';
import en from '@/locales/en.json';
import zh from '@/locales/zh.json';

const messages = {
	en,
	zh,
};

// 自动检测用户语言
const userLanguage = navigator.language || navigator.userLanguage;
const language = userLanguage.split('-')[0]; // 获取语言代码，如 'en', 'zh'
console.log(`Browser language: ${language}`);


const i18n = createI18n({
	legacy: false, // 必须设为 false
	locale: localStorage.getItem('userLanguage') || language, // 默认语言
	fallbackLocale: 'en', // 备用语言
	messages,
});

export default i18n;
